package com.medicine.sys.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.medicine.sys.entity.Role;
import com.medicine.sys.mapper.RoleMapper;
import com.medicine.sys.param.RoleParam;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.lang.reflect.InvocationTargetException;
import java.util.List;

@Service
public class RoleService extends ServiceImpl<RoleMapper, Role> {

    public IPage<Role> selectPageList(RoleParam roleParam){
        Page<Role> rolePage = new Page<>(roleParam.getPage(),roleParam.getSize());
        return page(rolePage,new QueryWrapper<Role>().lambda().like(StringUtils.isNotEmpty(roleParam.getName()),Role::getName,roleParam.getName()))
        /*.eq(StringUtils.isNotEmpty(),Role::getMerchantId,"").eq(StringUtils.isNotEmpty(),Role::getOrgId,""))*/;  //加入登录后补上
    }

    public List<Role> selectList(){
        return list(new QueryWrapper<Role>().lambda().eq(Role::getMerchantId,"").eq(Role::getOrgId,""));  //后续加入登录补上
    }

    public void install(Role role) throws Exception {
        Role role1 = new Role();
        BeanUtils.copyProperties(role1,role);
        saveOrUpdate(role1);
    }

    public Role getId(String id){
        return getById(id);
    }
}
